﻿namespace Text2Rss.Web.Code
{
	#region Using Directives
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.ServiceModel.Syndication;
	using System.Web;
	using System.Web.Mvc;
	using System.Xml;
	#endregion

	/// <summary>
	/// Action for Rss Feed
	/// </summary>
	public class RssActionResult : ActionResult
	{
		/// <summary>
		/// Gets of sets feed
		/// </summary>
		public SyndicationFeed Feed { get; set; }

		/// <summary>
		/// Outputs the feed to the response
		/// </summary>
		/// <param name="context">Context of controller</param>
		public override void ExecuteResult(ControllerContext context)
		{
			context.HttpContext.Response.ContentType = "application/rss+xml";

			Rss20FeedFormatter rssFormatter = new Rss20FeedFormatter(Feed);
			using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output))
			{
				rssFormatter.WriteTo(writer);
			}
		}
	}
}
